package emulator.unittest.assembler;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import emulator.assembler.SymbolTable;
import emulator.assembler.SymbolTableEntry;

public class SymbolTableTest {

	private SymbolTable table;

	@Before
	public void setUp() throws Exception {
		table = new SymbolTable();
		table.addSymbol(0x0073, "CHRGET", "Read next input char", SymbolTableEntry.SYMBOL_TYPE_CODE);
		table.addSymbol(0xC000, null, "Basic start", SymbolTableEntry.SYMBOL_TYPE_WORD);
		table.addSymbol(0xFD22, "RESET", null, SymbolTableEntry.SYMBOL_TYPE_CODE);
		// test for bug
		table.addSymbol(0xFD3F, null, "Check For A-ROM", SymbolTableEntry.SYMBOL_TYPE_CODE);
	}

	@Test
	public void testGetLabel() {
		assertNull(table.getJumpLabel(0x1234));
		assertEquals("CHRGET", table.getJumpLabel(0x0073));
		assertNull(table.getJumpLabel(0xC000));
		assertEquals("RESET", table.getJumpLabel(0xFD22));
		assertNull(table.getJumpLabel(0xFD3F));
	}

	@Test
	public void testLabelOrAddress() {
		assertEquals("$1234", table.getLabelOrAddress(0x1234));
		assertEquals("CHRGET", table.getLabelOrAddress(0x0073));
		assertEquals("$C000", table.getLabelOrAddress(0xC000));
		assertEquals("RESET", table.getLabelOrAddress(0xFD22));
	}

	@Test
	public void testLabelFromAddress() {
		assertEquals("L_1234", table.createJumpLabel(0x1234));
		assertEquals("CHRGET", table.createJumpLabel(0x0073));
		assertEquals("L_C000",table.createJumpLabel(0xC000));
		assertEquals("RESET",table.createJumpLabel(0xFD22));
		assertEquals("L_FD3F",table.createJumpLabel(0xFD3F));
		/* Check for modifications */
		assertNull(table.getJumpLabel(0xA000));
		assertEquals("L_1234", table.getJumpLabel(0x1234));
		assertEquals("CHRGET", table.getJumpLabel(0x0073));
		assertEquals("L_C000", table.getJumpLabel(0xC000));
		assertEquals("RESET", table.getJumpLabel(0xFD22));
		assertEquals("L_FD3F", table.getJumpLabel(0xFD3F));
	}

	@Test
	public void testGetRemark() {
		assertNull(null, table.getRemark(0x1234));
		assertEquals("Read next input char", table.getRemark(0x0073));
		assertEquals("Basic start",table.getRemark(0xC000));
		assertNull(null,table.getRemark(0xFD22));
	}

}
